package com.carmes.controller;

import com.carmes.entity.EquipmentNumber;
import com.carmes.entity.search.EquipmentNumberSearch;
import com.carmes.entity.view.EquipmentModel;
import com.carmes.service.EquipmentNumberService;
import com.carmes.util.DateUtils;
import com.carmes.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.*;

@Controller
@RequestMapping("/api/equipmentNumber")
public class EquipmentNumberController {

    @Autowired
    private EquipmentNumberService equipmentNumberService;

    /**
     * 查询
     * @return
     */
    @RequestMapping("/getTableCount")
    @ResponseBody
    public Result getTableCount(EquipmentNumberSearch obj) throws ParseException {
        Map map=new HashMap();
        map.put("gwList",obj.getGw());
        List<String> dateList= DateUtils.getDaysBetweenTwoDays(obj.getStrDate(),obj.getEndDate());
        map.put("dateList",dateList);
        List<EquipmentNumber> equipmentNumberList=this.equipmentNumberService.getTableCount(obj);
        map.put("equipmentNumberList",equipmentNumberList);
        List<EquipmentModel> equipmentModels=new ArrayList<>();
        for (EquipmentNumber equipmentNumber : equipmentNumberList) {
            EquipmentModel model=new EquipmentModel();
            model.setName(equipmentNumber.getGw());
            Integer[] num=new Integer[1];
            num[0]=equipmentNumber.getOee();
            model.setData(num);
            equipmentModels.add(model);
        }
        map.put("equipmentModels",equipmentModels);
        /*List<Integer> processqualities=this.equipmentNumberService.getTableCount(obj);
        map.put("processqualities",processqualities);
        List<Integer> customercomplaint=this.customercomplaintMapper.getTableCount();
        map.put("customercomplaint",customercomplaint);*/
        return Result.reOk("查询成功",map);
    }

}
